<div class="admin-head">
    <ul>
        <li class="on">发货地址</li>
    </ul>
</div>
<div class="table-body">
    <div class="search-tool">
        <form class="layui-form layui-form-pane">
            <div class="layui-inline">
                <div class="layui-input-inline seller-inline-3">
                    <input class="layui-input" autocomplete="off" placeholder="开始日期" name="start" id="start">
                </div>
                <div class="layui-input-inline seller-inline-3">
                    <input class="layui-input" autocomplete="off" placeholder="截止日期" name="end" id="end">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline seller-inline-3">
                    <select name="status" lay-verify="">
                        <option value="">全部状态</option>
                        <option value="0">待审核</option>
                        <option value="1">通过</option>
                        <option value="-1">拒绝</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <input type="text" name="search" lay-verify="title" placeholder="姓名、地址" class="layui-input">
                <span class="item-icon" lay-submit lay-filter="user-search" id="onsearch"><i class="layui-icon layui-icon-search"></i></span>
            </div>
        </form>
        <div class="func-btn">
            <a href="{:url('add')}" class="layui-btn layui-bg-blue layui-btn-sm">添加地址</a>
        </div>
    </div>
    <table id="list" lay-filter="list"></table>
</div>

<script type="text/html" id="addrTpl">
    {{d.area_name}}{{d.address}}
</script>
<script type="text/html" id="action">
    <a href="{:url('edit')}?id={{d.id}}" class="layui-btn layui-btn-sm">编辑</a>

    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
</script>
<script>
    layui.use(['form', 'layedit', 'laydate', 'table'], function () {
    	var table=layui.table,laydate=layui.laydate;
        var tableIn = table.render({
            elem: '#list',
            page: true,
            method:'post',
            url: "{:url('address')}",
            id: 'list',
            cols: [[
                {type: 'checkbox',title:'ID',align:'center',width:50},
                {field: 'name', align: 'center',title: '发货人',width:180},
                {field: 'mobile',align:'center',title: '联系电话',width:150},
                {field: 'address', align: 'center',title:'发货地址',width:420,templet:'#addrTpl'},
                {field: 'ctime_text', align: 'center',title: '添加时间',width:200},
                {align: 'center',toolbar:'#action'}
            ]]
        });
        laydate.render({
            elem:'#start',
            type:'datetime'
        });
        laydate.render({
            elem: '#end',
            type:'datetime'
        });
        //搜索
        layui.form.on('submit(user-search)', function (data) {
            layui.table.reload('list', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //行列表操作项事件
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('你确定要删除吗？', {icon: 3}, function (index) {
                    $.post("{:url('del')}",{ids:data.id},function(res){
                        if(res.status===200){
                            layer.msg('删除成功',{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>